local zunwei = fk.CreateSkill {
  name = "lvshi__zunwei&",
  mode_skill = true,
}

Fk:loadTranslationTable{
  ["lvshi__zunwei&"] = "尊威",
  [":lvshi__zunwei&"] = "出牌阶段开始时，你可摸一张牌，然后明置一张手牌。回合技，其他非先驱角色于此轮使用或打出与此牌花色相同的牌时，你可令其弃置一张牌。（X为主忠方存活角色数）",
  ["@lvshi__zunwei-round"] = "<b><font color=\"#FFD700\">尊威</font></b>",
  ["#lvshi__zunwei-invoke"] = "尊威：你可以令%dest弃置一张牌",
  ["#lvshi__zunwei-show"] = "尊威：请明置一张手牌",
}

local DIY = require "packages/diy_utility/diy_utility"

zunwei:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zunwei.name) and player.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = zunwei.name})
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, zunwei.name)
    local card = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      include_equip = false,
      pattern = ".",
      prompt = "#lvshi__zunwei-show",
      cancelable = false,
    })
    if #card > 0 then
      DIY.showCards(player, card)
      room:setPlayerMark(player, "@lvshi__zunwei-round", {Fk:getCardById(card[1]):getSuitString(true)})
    end
  end,
})

zunwei:addEffect(fk.CardUsing, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(zunwei.name) and #player:getTableMark("@lvshi__zunwei-round") > 0 then
      return player:getMark("lvshi__zunwei-turn") == 0 and player.room:getTag("prophet") ~= target.id and
      data.card:getSuitString(true) == player:getTableMark("@lvshi__zunwei-round")[1] and not target:isNude()
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = zunwei.name, prompt = "#lvshi__zunwei-invoke::"..target.id})
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "lvshi__zunwei-turn")
    player.room:askToDiscard(target, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      cancelable = false,
    })
  end,
})

zunwei:addEffect(fk.CardResponding, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(zunwei.name) and #player:getTableMark("@lvshi__zunwei-round") > 0 then
      return player:getMark("lvshi__zunwei-turn") == 0 and player.room:getTag("prophet") ~= target.id and
      data.card:getSuitString(true) == player:getTableMark("@lvshi__zunwei-round")[1] and not target:isNude()
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = zunwei.name, prompt = "#lvshi__zunwei-invoke::"..target.id})
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "lvshi__zunwei-turn")
    player.room:askToDiscard(target, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      cancelable = false,
    })
  end,
})

return zunwei
